package com.fit.pages.user;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.AnonymousAccess;
import com.fit.dao.user.UserDAO;
import com.fit.entities.user.User;
import com.fit.model.MD5;
import com.fit.pages.ErrorPage;


@AdminAccess

public class Add {

	@Property
	private User user;
	@Inject
	private UserDAO userDAO;
	@InjectPage
	private ErrorPage errorPage;

	Object onSuccess() {
		try {
			user.setPassword(MD5.md5(user.getPassword()));
			userDAO.save(user);
			return Browse.class;
		} catch (Exception e) {
			errorPage.setMessage("Greska prilikom brisanja zapisa korisnika! ");
			return errorPage;
		}

	}

}
